package chapter1;

import lombok.extern.slf4j.Slf4j;

/**
 * @author caiya
 * @date 2020/3/13 22:02
 */
@Slf4j
public class InheritableThreadLocalTest {
    private static final ThreadLocal<String> THREAD_LOCAL = new InheritableThreadLocal<>();

    public static void main(String[] args) {
        /**
         * InheritableThreadLocal：支持父线程中的 ThreadLocal 变量传递到子线程中
         */
        THREAD_LOCAL.set("hello world!");

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                log.debug("{}: {}", Thread.currentThread().getName(), THREAD_LOCAL.get());
            }
        });
        thread.start();

        log.debug("{}: {}", Thread.currentThread().getName(), THREAD_LOCAL.get());
    }
}
